package app

import (
	"gitee.com/mirzatsoft/wakit/config"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

type WebAppContext struct {
	DB     *gorm.DB
	Router *gin.Engine
	Logger *zap.Logger
	Config *config.Config
}

func NewContext(cfg *config.Config) (*WebAppContext, error) {
	db, err := gorm.Open(cfg.Web.Database.GetDialector(), &gorm.Config{})
	if err != nil {
		return nil, err
	}

	return &WebAppContext{
		DB:     db,
		Router: gin.Default(),
		Logger: zap.NewExample(),
		Config: cfg,
	}, nil
}
